#include <bits/stdc++.h>
#define re register
#define fst first
#define snd second
#define int long long
#define getid(x,y) ((x) * L + (y))
#define chmin(a,b) (a = min(a,b))
#define chmax(a,b) (a = max(a,b))

using namespace std;

typedef pair<int,int> pii;
const int N = 5e5 + 10,L = 1e6;
const int inf = 1e9 + 10;
int n;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
vector<pii> pt;
vector<int> g[N];
unordered_map<int,int> mark;

inline int read(){
    int r = 0,w = 1;
    char c = getchar();
    while (c < '0' || c > '9'){
        if (c == '-') w = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9'){
        r = (r << 3) + (r << 1) + (c ^ 48);
        c = getchar();
    }
    return r * w;
}

namespace Sub1{
    int ans,dis[N];

    inline void bfs(int s){
        queue<int> q;
        fill(dis,dis + n + 3,-1);
        dis[s] = 0; q.push(s);
        while (!q.empty()){
            int t = q.front(); q.pop();
            ans += dis[t];
            for (int v:g[t]){
                if (!~dis[v]){
                    dis[v] = dis[t] + 1; q.push(v);
                }
            }
        }
    }
    
    inline void solve(){
        int tot = 0;
        for (re int i = 1;i <= n;i++) bfs(i);
        printf("%lld",ans / 2);
    }
}

namespace Sub2{
    int ans;

    inline void solve(){
        int x = inf,y = inf,xx = -inf,yy = -inf;
        for (pii p:pt){
            chmin(x,p.fst); chmin(y,p.snd);
            chmax(xx,p.fst); chmax(yy,p.snd);
        }
        for (re int i = x;i <= xx;i++){
            int a = i * (i - x + 1) - (x + i) * (i - x + 1) / 2;
            int b = (i + xx) * (xx - i + 1) / 2 - (xx - i + 1) * i;
            ans += ((yy - y + 1) * (yy - y + 1) * (a + b));
        }
        for (re int i = y;i <= yy;i++){
            int a = i * (i - y + 1) - (y + i) * (i - y + 1) / 2;
            int b = (i + yy) * (yy - i + 1) / 2 - (yy - i + 1) * i;
            ans += ((xx - x + 1) * (xx - x + 1) * (a + b));
        } printf("%lld",ans / 2);
    }
}

signed main(){
    freopen("game.in","r",stdin);
    freopen("game.out","w",stdout);
    n = read();
    for (re int i = 1,x,y;i <= n;i++){
        x = read(),y = read();
        pt.push_back({x,y});
        mark[getid(x,y)] = i;
    }
    for (re int i = 0;i < pt.size();i++){
        int tx = pt[i].fst,ty = pt[i].snd;
        for (re int d = 0;d < 4;d++){
            int nx = tx + dx[d],ny = ty + dy[d];
            if (mark.count(getid(nx,ny))) g[i + 1].push_back(mark[getid(nx,ny)]);
        }
    }
    if (n <= 4e3) Sub1::solve();
    else Sub2::solve();
    return 0;
}